//前缀和
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<long long>dp(n + 1);
    int temp = 0;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        dp[i + 1] = dp[i] + temp;
    }
    for (int i = 0; i < q; i++) {
        int left, right;
        cin >> left >> right;
        cout << dp[right] - dp[left - 1] << endl;
    }
}
// 二维前缀和
#include <iostream>
#include<vector>
using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<long long>>dp(n + 1, vector<long long>(m + 1));
    int temp;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> temp;
            dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] + temp - dp[i][j];
           // cout << dp[i + 1][j + 1] << ' ';
        }
       // cout << endl;
    }
    int x1, y1, x2, y2;
    for (int i = 0; i < q; i++) {
        cin >> x1 >> y1 >> x2 >> y2;
        cout << dp[x2][y2] + dp[x1 - 1][y1 - 1] - dp[x2][y1 - 1] - dp[x1 - 1][y2] <<
             endl;
    }
}
// 64 位输出请用 printf("%lld")